<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>小白技术趴</title>
    <link rel="stylesheet" href="/css/style.css"/>
    <link rel="stylesheet" href="/css/editormd.preview.css"/>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="shortcut icon" href="/images/favicon.ico" type="image/x-icon"/>
    <style>
        li {
            list-style: decimal
        }
        .editormd-html-preview {
            width: 70%;
            margin: 0 10% 0 20%;
        }
        .layui-tree-txt{
            color: white;
        }
        .layui-tree-entry{
            height: 30px;
        }
        .layui-side-scroll{
            text-align: left;
        }
        .layui-tree-entry:hover{
            background-color: #23262e;
        }
    </style>
</head>

<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">小白技术趴</div>
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item">
                ${checkedFile}
            </li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <!--<li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
                    贤心
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="">基本资料</a></dd>
                    <dd><a href="">安全设置</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="">退了</a></li>-->
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll" id = "menu">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <!--<ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">所有商品</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;">列表一</a></dd>
                        <dd><a href="javascript:;">列表二</a></dd>
                        <dd><a href="javascript:;">列表三</a></dd>
                        <dd><a href="">超链接</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">解决方案</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;">列表一</a></dd>
                        <dd><a href="javascript:;">列表二</a></dd>
                        <dd><a href="">超链接</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item"><a href="">云市场</a></li>
                <li class="layui-nav-item"><a href="">发布商品</a></li>
            </ul>-->
        </div>
    </div>

    <div class="layui-body">
        <textarea style="display: none" id="append-test">${content}</textarea>
        <!-- 内容主体区域 -->
        <div style="padding: 15px;" id = "markdownView"></div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © lizk.xyz - 小白技术趴 | 
	<a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11011202002157" style="display:inline-block;text-decoration: none;height: 44px;line-height: 44px;"><img src="http://www.beian.gov.cn/portal/download?token=e5ca64f1-bc4e-4240-ae08-fef7543b3497" style="/* float:left; */"><p style="float: right;/* height:20px; *//* line-height:20px; */margin: 0px 0px 0px 5px;color:#939393;">京公网安备 11011202002157号</p></a>
    </div>
</div>
<script src="/js/layui/layui.js" charset="utf-8"></script>
<script src="/js/jquery.min.js"></script>
<script src="/js/marked.min.js"></script>
<script src="/js/prettify.min.js"></script>

<script src="/js/raphael.min.js"></script>
<script src="/js/underscore.min.js"></script>
<script src="/js/sequence-diagram.min.js"></script>
<script src="/js/flowchart.min.js"></script>
<script src="/js/jquery.flowchart.min.js"></script>

<script src="/js/editormd.min.js"></script>
<script>
    //JavaScript代码区域

    function changePath(that) {
        let o = $(that);
        console.log(o);
        console.log(o.attr("filePath"));
        window.location = "/file/" + o.attr("filePath");
    }

    $(function () {
        let markdown = $("#append-test").text();
        editormd.markdownToHTML("markdownView", {
            markdown: markdown,//+ "\r\n" + $("#append-test").text(),
            //htmlDecode      : true,       // 开启 HTML 标签解析，为了安全性，默认不开启
            htmlDecode: "style,script,iframe",  // you can filter tags decode
            //toc             : false,
            tocm: true,    // Using [TOCM]
            //tocContainer    : "#custom-toc-container", // 自定义 ToC 容器层
            //gfm             : false,
            //tocDropdown     : true,
            // markdownSourceCode : true, // 是否保留 Markdown 源码，即是否删除保存源码的 Textarea 标签
            emoji: true,
            taskList: true,
            tex: true,  // 默认不解析
            flowChart: true,  // 默认不解析
            sequenceDiagram: true,  // 默认不解析
        });
    });

    layui.use(['element','tree', 'util'], function () {
        var element = layui.element;
        var tree = layui.tree;
        var util = layui.util;

        $.post("/dir/all", function (res) {

            show(res)
            console.log(res)

            //无连接线风格
            tree.render({
                elem: '#menu'
                , data: res
                ,id: 'demoId'
                ,accordion:true
                ,showLine:false
                , click : function(obj){
                    if(!obj.data.isDir){
                        window.location = "/file/" + obj.data.path;
                    }
                }
            });

            //entryArray = $(".layui-tree-spread").children(".layui-tree-pack").children(".layui-tree-set")
            $(".layui-tree-set.layui-tree-spread:not(.layui-tree-setHide)").find(".layui-tree-entry:first").attr("style","background-color: #138e04;");


        })

    });

    function show(arr) {
        for (let i = 0; i < arr.length; i++) {
            item = arr[i];
            if (item.children){
                result = show(item.children)
                if (result){
                    arr[i].spread = true;
                    return true;
                }
            }else{
                if (item.path.startsWith("${checkedFile}")){
                    arr[i].spread = true;
                    return true
                }
            }
        }
    }


</script>
</body>
<!--<body>
<div id="layout">
    <header style="height: 60px;
    display: block;
    z-index: 1000;
    background-color: white;
    position: fixed;
    width: 100%;
    border-bottom-color: #f2f2f2;
    border-bottom-style: solid;
    border-bottom-width: 1px;
    top: 0px;">
        <h1 style="margin-left: 20%" id="fileName"></h1>
    </header>
    <div id="menu">

    </div>
    <div id="test-editormd-view">
    </div>

    <textarea style="display: none" id="append-test"></textarea>
</div>
<script src="/js/jquery.min.js"></script>
<script src="/js/marked.min.js"></script>
<script src="/js/prettify.min.js"></script>

<script src="/js/raphael.min.js"></script>
<script src="/js/underscore.min.js"></script>
<script src="/js/sequence-diagram.min.js"></script>
<script src="/js/flowchart.min.js"></script>
<script src="/js/jquery.flowchart.min.js"></script>

<script src="/js/editormd.min.js"></script>
<script type="text/javascript">

    let checkedFile = "${checkedFile}";

    function showOneLevel(that, res, index) {
        let retract = index * 4
        console.log("retract:", retract)

        for (let i = 0; i < res.length; i++) {
            if (res[i].isDir) {
                var divObject = $('<div></div>');
                that.append(divObject)
                divObject.append('<span class="dirSpan spanMargin' + retract + '" isFile="' + !res[i].isDir + '" filePath="' + res[i].path + '" onclick="#">' + res[i].name + '</span>')
                showOneLevel(divObject, res[i].next, index + 1)
            } else {
                let isCheck = ""
                if (checkedFile == res[i].path) {
                    isCheck = "checked"
                }
                var divObject = $('<div></div>');
                that.append(divObject)
                divObject.append('<span class="fileSpan ' + isCheck + ' spanMargin' + retract + '" isFile="' + !res[i].isDir + '" filePath="' + res[i].path + '" onclick="changePath(this)">' + res[i].name + '</span>')
            }
        }
    }


    function changePath(that) {
        let o = $(that);
        console.log(o);
        console.log(o.attr("filePath"));
        window.location = "/file/" + o.attr("filePath");
    }

    $(function () {
        $.post("/dir/all", function (res) {
            //showOneLevel($("#menu"),res,0);
            layui.use(['tree', 'util'], function () {
                var tree = layui.tree
                //无连接线风格
                tree.render({
                    elem: '#menu'
                    , data: res
                    , showLine: false  //是否开启连接线
                });
            });

        })
        let markdown = $("#append-test").text();
        editormd.markdownToHTML("test-editormd-view", {
            markdown: markdown,//+ "\r\n" + $("#append-test").text(),
            //htmlDecode      : true,       // 开启 HTML 标签解析，为了安全性，默认不开启
            htmlDecode: "style,script,iframe",  // you can filter tags decode
            //toc             : false,
            tocm: true,    // Using [TOCM]
            //tocContainer    : "#custom-toc-container", // 自定义 ToC 容器层
            //gfm             : false,
            //tocDropdown     : true,
            // markdownSourceCode : true, // 是否保留 Markdown 源码，即是否删除保存源码的 Textarea 标签
            emoji: true,
            taskList: true,
            tex: true,  // 默认不解析
            flowChart: true,  // 默认不解析
            sequenceDiagram: true,  // 默认不解析
        });
    });
</script>
</body>-->
</html>
